<?php

namespace randy\tools\enum;

/**
 * 枚举基类 , 仅供枚举使用
 */
trait BaseEnum
{
    public static function keyValues() : array
    {
        $result = [];
        foreach (self::cases() as $case) {
            $result[$case->value] = $case->label();
        }
        return $result;
    }

    public function label() : string
    {
        $refObject = new \ReflectionEnumUnitCase(self::class, $this->name);
        $attributes = $refObject->getAttributes();
        foreach ($attributes as $attribute) {
            $args = $attribute->getArguments();
            return $args[0];
        }
        return '';
    }
}